<template>
    <el-card shadow="never">
        <div slot="header">
            <span>
                <b class="u-f-16">地址列表</b>
            </span>
        </div>

        <el-table :data="tableData">
            <el-table-column label="序号" type="index" width="60"></el-table-column>
            <el-table-column label="联系电话" prop="take_phone"></el-table-column>
            <el-table-column label="联系人" prop="take_name"></el-table-column>

            <el-table-column label="省" prop="province"></el-table-column>
            <el-table-column label="市" prop="city"></el-table-column>
            <el-table-column label="区" prop="district"></el-table-column>
            <el-table-column label="详细地址" prop="detail_address"></el-table-column>
            <el-table-column label="经度" prop="lng"></el-table-column>
            <el-table-column label="纬度" prop="lat"></el-table-column>
            <el-table-column label="是否默认">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.is_default===1">是</el-tag>
                    <el-tag type="info" v-else>否</el-tag>
                </template>
            </el-table-column>
            <!-- <el-table-column label="操作" width="80" v-if="hasPerm('delAddressBtn')">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="handleDelete(scope.row.id)">删除</el-button>
                </template>
            </el-table-column> -->
        </el-table>
    </el-card>
</template>

<script>
    export default {
        name:'userAddress',
        props:{
            userId:{
                type:String
            }
        },
        data() {
            return {
                tableData:[]
            }
        },
        methods:{
            getAddressList(){
                this.$api.user.address({user_id:this.userId}).then(response => {
                    if(response.code==1){
                        this.tableData = response.data.pageList
                    }
                })
            },
            handleDelete(id){
                this.$confirm('确认删除该数据吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$api.user.delAddress(id).then(response => {
                        if(response.code==1){
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            })
                            this.getAddressList()
                        }
                    })
                }).catch(()=>{})
            }
        },
        created(){
            this.getAddressList()
        }
    }
</script>
